package com.joint.base.dao.impl;


import com.fz.us.base.bean.BaseEnum;
import com.joint.base.dao.CompanyDao;
import com.joint.base.dao.TaskFlowDao;
import com.joint.base.entity.*;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import java.util.List;

/**
 * Dao实现类 - 岗位
 * ============================================================================
 * 版权所有 2013 。
 * 
 * @author 
 * @version 0.1 2013-1-16
 * ============================================================================
 */

@Repository
public class TaskFlowDaoImpl extends BaseEntityDaoImpl<TaskFlow, String> implements TaskFlowDao {

    @Override
    public List<Users> findUsersByTaskFlow(String taskId) {
        Assert.notNull(taskId,"taskId is required");
        String hql="SELECT users from TaskFlow where taskId =:taskId and state = :state";
        List<Users> usersList =  getSession().createQuery(hql).setParameter("taskId", taskId)
                .setParameter("state", BaseEnum.StateEnum.Enable).list();
        return  usersList;
    }

    @Override
    public List<TaskFlow> getTaskFlowByCreatetime() {
        String hql = "from TaskFlow where state = :state order by createDate asc";
        List<TaskFlow> taskFlowList =  getSession().createQuery(hql).setParameter("state", BaseEnum.StateEnum.Enable).list();
        return  taskFlowList;
    }

    @Override
    public List<TaskFlow> getInfoByTaskEntity(TaskEntity taskEntity) {
        String hql = "from TaskFlow where state = :state and taskEntity = :taskEntity order by createDate asc";
        List<TaskFlow> taskFlowList = getSession().createQuery(hql).setParameter("state", BaseEnum.StateEnum.Enable)
                .setParameter("taskEntity", taskEntity).list();
        return taskFlowList;
    }

    @Override
    public List<TaskFlow> getInfoByTaskStepBrief(TaskEntity taskEntity, StepBrief stepBrief) {
        String hql = "from TaskFlow where state = :state and taskEntity = :taskEntity and stepBrief = :stepBrief order by createDate asc";
        List<TaskFlow> taskFlowList = getSession().createQuery(hql).setParameter("state", BaseEnum.StateEnum.Enable)
                .setParameter("taskEntity", taskEntity).setParameter("stepBrief", stepBrief).list();
        return taskFlowList;
    }
}